
/*
 * This is GPL v2 licensed code. See the file LICENSE in the
 * source distribution, or www.gnu.org/copyleft/gpl.html, for
 * more information.
 *
 * Copyright (C) by Håkan Lindqvist 2006, 2007
 */

package PolicyToolGui;


import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.ResourceBundle;


/** 
 * This class is the main part used to read properties.
 */
public abstract class PropertyLoader {
	private Properties props;


	/** 
	 * Constructor.
	 *
	 * @param file The property file to load.
	 * @throws IOException If something goes wrong when loading
	 *         the properties file.
	 */
	protected PropertyLoader(String file) throws IOException{
		props = new Properties();
		InputStream fin = PropertyLoader.class.getResourceAsStream(file);

		if (fin == null) {
			throw new IOException("Failed to fetch properties file: " + file);
		}

		props.load(fin);
		fin.close();
	}


	/** 
	 * Fetches a property.
	 * 
	 * @param key The property te fetch a value for.
	 * @return The property.
	 */
	protected String getPropertyByKey(String key){
		if (key == null){
			return null;
		}

		String val = props.getProperty(key);

		if (val == null){
			System.err.println("key = '" + key + "' resulted in empty string");
			return new String();
		}
		return val;
	}
}
